package com.ai.module.user.service.impl;

import com.ai.module.user.domain.entity.UserTaskEntity;
import com.ai.module.user.domain.req.UserRobotReq;
import com.ai.module.user.domain.vo.UserTaskVo;
import com.ai.module.user.mapper.UserTaskMapper;
import com.ai.module.user.service.UserTaskService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author: MrHe
 * @create: 2024-01-08 22:44
 * @description:
 **/
@Service
public class UserTaskServiceImpl extends ServiceImpl<UserTaskMapper, UserTaskEntity> implements UserTaskService {

    @Override
    public Page<UserTaskVo> findByRobot(UserRobotReq req) {
        Page<UserTaskVo> ipage = new Page<>(req.getPage(), req.getSize());
        Page<UserTaskVo> iPageList = this.baseMapper.findByRobot(ipage, req.getRobotId());
        List<UserTaskVo> records = iPageList.getRecords();
        records.forEach(
                t->{
                    String originUrlList = t.getOriginUrlList();
                    if (StringUtils.hasText(originUrlList)){
                        t.setImageUrlList(Arrays.asList(originUrlList.split(",")));
                    }
                }
        );
//        int page = req.getPage();
//        if (page == 1){
//            Collections.reverse(records);
//        }
//        iPageList.setRecords(records);
        return iPageList;
    }
}
